package com.orange.cetback.controller.admin;

import com.orange.cetback.common.vo.PageResult;
import com.orange.cetback.common.vo.Result;
import com.orange.cetback.pojo.dto.MaterialDTO;
import com.orange.cetback.pojo.entity.Materials;
import com.orange.cetback.pojo.vo.MaterialVO;
import com.orange.cetback.service.MaterialsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("AdminMaterialController")
@RequestMapping("/admin-api/material")
@Tag(name = "试卷材料接口")
public class MaterialsController {
    @Autowired
    private MaterialsService materialsService;

    @Operation(summary = "分页查询试卷材料信息")
    @PostMapping("/page")
    public Result<PageResult<MaterialVO>> page(@RequestBody MaterialDTO materialDTO) {
        log.info("分页查询试卷材料信息：{}", materialDTO);
        PageResult<MaterialVO> pageResult = materialsService.pageQuery(materialDTO);
        return Result.success(pageResult);
    }

    @Operation(summary = "获取试卷材料详细信息")
    @GetMapping("/{id}")
    public Result<Materials> getInfo(@PathVariable Integer id) {
        Materials materials = materialsService.getById(id);
        return Result.success(materials);
    }

    @Operation(summary = "新增试卷材料信息")
    @PostMapping("/")
    public Result<String> save(@RequestBody Materials materials){
        materialsService.save(materials);
        return Result.success("新增试卷材料信息成功");
    }

    @Operation(summary = "修改试卷材料信息")
    @PutMapping("/")
    public Result<String> update(@RequestBody Materials materials){
        materialsService.updateById(materials);
        return Result.success("修改试卷材料信息成功");
    }
}
